package com.yunti.springboot.util;


import java.time.LocalDate;

public class SemesterUtil {

    //获取当前学年
    public static int getGradeYear(){
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        int year = currentDate.getYear();
        int month = currentDate.getMonthValue();
        if(month >= 8){
            return year;
        }
        return year - 1;
    }

    //通过年级(1,2,3)获取当前学年
    public static int getNowSemesterByStuYear(int stuYear){
        //获取当前学年
        int year = GradeYearUtil.getGradeYearByYear(stuYear);
        LocalDate currentDate = LocalDate.now();
        int month = currentDate.getMonthValue();
        int semester = year * 2;
        if(month >= 8){
            semester--;
        }
        return semester;
    }

    //通过年级(1,2,3)获取当前学年
    public static int getNowSemesterByYear(int year){
        //获取当前学年
        LocalDate localDate = LocalDate.now();
        int month = localDate.getMonthValue();
        int semester = year * 2;
        if(month >= 8){
            semester--;
        }
        return semester;
    }
}
